#ifndef CHESS_PIECES_H
#define CHESS_PIECES_H

#include <QObject>
#include <QWidget>
#include <QtMath>
#include <QDebug>

typedef struct _Position //虚拟坐标
{
    unsigned int x;
    unsigned int y;
} Position;
enum CAMP //阵营
{
    RED = 0,
    BLACK = 1
};
enum _Chess_TYPE //棋子
{
    CarLeft = 0,
    CarRight,
    HorseLeft,
    HorseRight,
    ElephantLeft,
    ElephantRight,
    BachelorLeft,
    BachelorRight,
    GunLeft,
    GunRight,
    Will,
    Redarms1,
    Redarms2,
    Redarms3,
    Redarms4,
    Redarms5,
};

enum Boundary //临界
{
    Boundary_mini_x = 0,
    Boundary_max_x = 8,
    Boundary_mini_y = 0,
    Boundary_max_y = 9,
    Mid_red = 4,
    Mid_black = 5,
    Will_min_red_x = 3,
    Will_max_red_x = 5,
    Will_min_red_y = 0,
    Will_max_red_y = 2,
    Will_min_black_x = 3,
    Will_max_black_x = 5,
    Will_min_black_y = 7,
    Will_max_black_y = 9,
};

typedef struct _Chess_info
{
    int camp;
    int chess_type;
    Position pos;
} ChessInfo;

class chess_pieces
{
    // Q_OBJECT
protected:
    int camp;         //阵营
    int chess_type;   //棋子类型
    Position pos;     //棋子的虚拟位置
    QString filepath; //棋子的名称

    //判断目标棋子位置是否有自己人
    bool IsSelfChess(int camp, QPoint target_pos, QVector<chess_pieces> &red, QVector<chess_pieces> &black);

    //判断兵走子
    bool Redarms_Cache(int Camp, QPoint target_pos, QVector<chess_pieces> &red, QVector<chess_pieces> &black);
    //判断炮走子
    bool Gun_Cache(int Camp, QPoint target_pos, QVector<chess_pieces> &red, QVector<chess_pieces> &black);
    //判断将走子
    bool Will_Cache(int Camp, QPoint target_pos, QVector<chess_pieces> &red, QVector<chess_pieces> &black);
    // 判断仕走子
    bool Bachelor_Cache(int Camp, QPoint target_pos, QVector<chess_pieces> &red, QVector<chess_pieces> &black);
    // 判断象走子
    bool Elephant_Cache(int Camp, QPoint target_pos, QVector<chess_pieces> &red, QVector<chess_pieces> &black);
    // 判断车走子
    bool car_Cache(int Camp, QPoint target_pos, QVector<chess_pieces> &red, QVector<chess_pieces> &black);
    // 判断马走子
    bool houre_Cache(int Camp, QPoint target_pos, QVector<chess_pieces> &red, QVector<chess_pieces> &black);

public:
    chess_pieces(int camp, int chesstype, Position pos, QString filepath); //构造函数
    Position getPosition();                                                //返回棋子的虚拟坐标
    QString getfilepath();                                                 //返回名称
    void setPosition(const Position &pos);                                 //设置棋子的坐标
    int getChessType();                                                    //返回棋子的标识信息
    bool IsActionEfficacious(int Camp, QPoint target_pos, QVector<chess_pieces> &red, QVector<chess_pieces> black);
    ChessInfo getChessInfo();
};

#endif // CHESS_PIECES_H
